<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/css/bootstrap.css "></s:url>"/>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/css/Reset.css "></s:url>"/>
    <%--本页面css--%>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/css/index/index.css "></s:url>"/>
    <%--模态框css--%>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/css/modal.css "></s:url>"/>
    <%--分页css--%>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/css/pager.css "></s:url>"/>
    <%--日期控件--%>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/common/jedate/test/jeDate-test.css"></s:url>"/>
    <link rel="stylesheet" href="<s:url value=" /assets/dist/common/jedate/skin/jedate.css"></s:url>"/>
    <script src="<s:url value="/assets/dist/common/jedate/src/jedate.js"></s:url>"></script>
    <style>
        <%--修改模态框样式--%>
        .modal-content {
            border-radius: 0;
            box-shadow: 0 -2px 15px rgba(0, 0, 0, .5);
        }

        .modal-content h4 {
            font-size: 18px;
        }

        /*按钮样式*/
        .sel-course {
            padding: 6px 25px;
            background: rgba(86, 169, 216, 1);
            border: 0;
            border-radius: 10px;
            color: #fff;
        }

        .sel-red {
            display: inline-block;
            padding: 5px 20px;
            background-color: #FF4653;
            color: #fff;
        }

        .searchs em {
            display: block;
            margin-bottom: 5px;
        }
        #remind{
            position: absolute;
            top: 70px;
            left: 18px;
            font-size: 18px;
            color: rgba(245, 74, 89, 1);
        }
        /*<span class="span sel-red">选修</span>*/
    </style>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container" style="background-color: #F7F7F7;">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row no-margin  mian-course" style="margin-bottom: 20px !important;">
                    <div class="col-xs-12">
                        <div class="floor-box clear">
                            <div class="tab-content">
                                <div class="searchs">
                                    <!-- 第一行 -->
                                    <div class="row">
                                        <div class="col-xs-2" style="font-size: 18px;">
                                            <em>选课开始日期</em>
                                            <%--<input id="start-time" type="text" value="${ba02.BAB201}"--%>
                                                   <%--placeholder="请选择开始时间">--%>
                                            <input type="text" class="jeinput" id="start-time"   value="${ba02.BAB201}"  placeholder="请选择开始时间">
                                        </div>
                                        <div class="col-xs-2" style="font-size: 18px;">
                                            <em>选课结束日期</em>
                                            <%--<input id="finish-time" type="text" value="${ba02.BAB202}"--%>
                                                   <%--placeholder="请选择结束时间">--%>
                                            <input type="text" class="jeinput"  value="${ba02.BAB202}" id="finish-time" placeholder="请选择结束时间">

                                        </div>
                                        <div class="col-xs-2" style="font-size: 18px;">
                                            <em>第二阶段开始日期</em>
                                            <%--<input id="second-time" type="text" value="${ba02.BAB203}"--%>
                                                   <%--placeholder="第二阶段开始时间">--%>
                                            <input type="text" class="jeinput" value="${ba02.BAB203}"  id="second-time" placeholder="第二阶段开始时间">

                                        </div>
                                        <div class="col-xs-2" style="font-size: 18px;position: relative;">
                                            <em>当前学期</em>
                                            <select  id="semester" >
                                                <option value="${bab205}" >${bab205Name}</option>

                                                <option class="semester_first" value="2018A">2018年第一学期</option>
                                                <option class="semester_second" value="2018B">2018年第二学期</option>
                                            </select>
                                            <div id="remind">
                                                <em class="font-red-remind"></em>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 第三行  查询按钮 -->
                                    <div class="row query-area">
                                        <div class="col-xs-12">
                                            <button class="searchs-btn btn">
                                                <span class="search glyphicon glyphicon-search"></span>&nbsp;&nbsp;&nbsp;确认修改
                                            </button>
                                            <button id="start-again" class=" btn" data-toggle="modal" data-target="#myModal-confirm">
                                                <span class="search glyphicon glyphicon-search"></span>&nbsp;&nbsp;&nbsp;重新开始
                                            </button>
                                        </div>
                                    </div>




                                </div>
                            </div>
                            <!-- tab 容器 -->
                        </div>
                        <!-- floor-box 容器 -->
                    </div>
                </div>
                <div>&nbsp;</div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
    <!-- 是否确认重新开始模态框 -->
    <div class="modal fade" id="myModal-confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
         data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">消息对话框</h4>
                </div>
                <div class="modal-body" style="font-size: 16px;">是否确认重新开始？？</div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="confirm-start" onclick="confirmStart()">确认</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
    <!-- dialog -->
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>
<!-- footer -->
<script src="<s:url value="/assets/dist/js/jquery.min.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script src="<s:url value="/assets/dist/js/bootstrap.min.js"></s:url>"></script>
<script src="<s:url value="/assets/dist/js/pager.js"></s:url>"></script>
<%--日期插件--%>
<script src="<s:url value="/assets/dist/common/jedate/test/demo.js"></s:url>"></script>


<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/sys/courseMamage/"></s:url>/"

    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['', '课程类别', '课程性质', '课程名称', '名额', '班级', '开课系', '学分', '上课时间', '上课地点', '可选/已选'];
    //jqgrid表格中每一行的信息模型
    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'bab007', index: 'bab007', width: 60, editable: true},
        {name: 'bab008', index: 'bab008', width: 60, editable: true},
        {name: 'bab002', index: 'bab002', width: 60, editable: true},
        {name: 'bab003', index: 'bab003', width: 60, editable: true},
        {name: 'bab004', index: 'bab004', width: 60, editable: true},
        {name: 'openDepartment', index: 'openDepartment', width: 60, editable: true},
        {name: 'credits', index: 'credits', width: 60, editable: true},
        {name: 'bab005', index: 'bab005', width: 60, editable: true},
        {name: 'bab004', index: 'bab004', width: 60, editable: true},
        {name: 'orSelect', index: 'userCount', width: 60, editable: true}

    ];

    //jqgrid的具体执行方法
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",

    });

    /*//加载查询对话框
    $("#queryDialog").load(getUrl("filter"));*/

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    //选课按钮t
    function selectcourse(cellvalue, options, rowObject, state) {
        /* console.log("分割线");
         console.log(options);*/
        var imgeHtml = " <button class=\"sel-course\"  data-toggle=\"modal\" data-target=\"#myModal\"  onclick=\"myclick('" + options.rowId + "')\" >选课</button> ";

        return imgeHtml;
    }

    function myclick(ids) {
        /* console.log(ids);
         $("#gridTable").trigger("reloadGrid");  //取消所有的勾选、
         showEditView();
         $("#gridTable").jqGrid('setSelection',ids); //勾选当前
*/

        loadDialog({
            // dialogTitle: '投注',
            dialogUrl: getUrl("edit"),
            dialogFoot: '<button id="save" class="btn-style btn btn-primary" onclick="create()">保存修改</button>\n' +
            '\t\t\t\t<button id="return-course" class="btn-style  btn btn-danger">退课</button><button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>'
        });
    }

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("edit"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //显示编辑对话框
    function showEditView() {
        showEditDialog({
            tableId: "#gridTable",
            // dialogTitle: "更新对话框",
            dialogUrl: getUrl("edit"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn">更新</button>' +
            '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    //双击
    $("#gridTable").dblclick(function (e) {
        // showView();

        console.log(e);
        showEditView();
    });

    /**判断是改变投注点数值
     * changeVlue()
     *
     * */

    //执行更新操作
    function edit() {
        //判断是否提交空值
        if ($("#AAB996").val() == "") {
            //调用提示框
            $.lightTip.error('投注点数不能为空！请重新输入！', 1000);
            return;
        }
        if ($("#AAB996old").val() === $("#AAB996").val()) {
            $.lightTip.error('未修改点数，无法更新！', 1000);
            return;
        }
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("edit"),
            tableId: "#gridTable",
            successMessage: "保存修改成功",
            // successTitle: '更新对话框',
            //failMessage: '保存修改失败',
            failTitle: '消息对话框'
        });
    }
    jeDate("#start-time", {
        format: "YYYY-MM-DD hh:mm",
        method: {
            choose: function (params) {
                console.log(params);
            }
        },
    });
    jeDate("#finish-time", {
        format: "YYYY-MM-DD hh:mm"
    });
    jeDate("#second-time", {
        format: "YYYY-MM-DD hh:mm"
    });


    $(".searchs-btn").click(function () {
        // var test = new RegExp(/-/g);
        var startTime = $("#start-time").val().replace(/-|\s|:|\//g, '');;//开始日期
        var finishTime = $("#finish-time").val().replace(/-|\s|:|\//g, '');;//结束日期
        var secondTime = $("#second-time").val().replace(/-|\s|:|\//g, '');;//结束日期
        var selSemester  =   $("#semester option:selected").val();//学期
        console.log(startTime + "----" + finishTime+"--"+secondTime + "--" + selSemester);
        // debugger;
        if (Number(startTime) == "" || Number(finishTime) == "" || Number(secondTime) == "" || Number(selSemester) == "" ) {
            //调用提示框
            $.lightTip.error('日期选项和学期选项不能为空！', 1000);
            return;
        }
        if ((Number(startTime) > Number(secondTime)) || (Number(secondTime) > Number(finishTime))) {
            $.lightTip.error('第二阶段时间必须介于开始时间和结束时间！', 1000);
            return;
        }
        if (Number(startTime) > Number(finishTime)) {
            //调用提示框
            $.lightTip.error('开始时间不能大于结束时间！', 1000);
            return;
        } else {
            $.ajax({
                dataType: "json",
                type: "POST",
                data: JSON.stringify({bab201: $("#start-time").val(), bab202: $("#finish-time").val(), bab203: $("#second-time").val(),bab205:selSemester}),
                contentType: 'application/json;charset=UTF-8',
                url: '/sys/courseMamage/changedate',
                success: function (datas) {
                    //调用提示框
                    if (datas.code == "200") {
                        $.lightTip.success(datas.message, 1000);
                    }else
                    {
                        $.lightTip.success("更新错误，请联系管理员", 1000);
                    }
                    console.log(datas);
                }
            })
        }


    });



    /*
    * confirmStart()  重新开始
    * */
    function confirmStart(){
        $.ajax({
            dataType: "json",
            type: "GET",
            //data: JSON.stringify({bab201: startTime,bab202:finishTime,bab203:secondTime}),
            //contentType: 'application/json;charset=UTF-8',
            url: '/sys/courseMamage/restart',
            success: function (datas) {
                console.log(66666666);
                console.log(datas);
                if(datas.code == "200"){
                    $('#myModal-confirm').modal('hide');//成功后关闭模态框
                }
            }
        })
    }

    //当前学期操作
    $(function () {
        var date = new Date;
        var currentYear = date.getFullYear();
        var currentMonth = date.getMonth()+1;
        console.log(currentYear,currentMonth);
        $("#semester .semester_first").html(currentYear+"年第一学期");
        $("#semester .semester_second").html(currentYear+"年第二学期");
        $("#semester .semester_first").val(currentYear+"A");
        $("#semester .semester_second").val(currentYear+"B");

         //选择学期操作
        $("#semester").change(function () {
            var  selSemester  =   $("#semester option:selected").val();//学期
            console.log(selSemester);
            //点击select事件
            $.ajax({
                type: "POST",
                dataType: "json",
                data: JSON.stringify({bab205:selSemester}),
                contentType: 'application/json;charset=UTF-8',
                url: '/sys/courseMamage/isOverChoose',
                success: function (res) {
                    console.log(res);
                    if(res.code != "200"){
                        $(".font-red-remind").html(res.message);
                    }else{
                        $(".font-red-remind").html("");
                    }

                }
            })

        });
      });







    //显示查询对话框

    //显示查询对话框
    /*var queryDialog = $("#queryDialog");
    $("#query").click(function() {
        showDialog({
            dialogTitle: '查询对话框',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
            "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
            "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {
        seachJqgird("#gridTable","#formDialog form");
        $("#formDialog").modal('hide');
    }

    //更新操作
    $("#edit").click(function() {
        showEditView();
    });





    //删除
    $("#delete").click(function() {
        showDeleteView();
    });

    //显示删除对话框
    function showDeleteView() {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    }

    //显示创建对话框
    $("#create").click(function(){
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
            '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }*/



</script>

</body>
</html>